﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace zmMoniter
{
    public class Extent
    {
        public double dMinX;
        public double dMinY;
        public double dMaxX;
        public double dMaxY;
        public Extent()
        {
            dMinX =999999999;
            dMinY = 999999999;
            dMaxX = -9999999990;
            dMaxY = -999999999;
        }
        public Extent(double dminx,double dminy,double dmaxx,double dmaxy)
        {
            dMinX = dminx;
            dMinY = dminy;
            dMaxX = dmaxx;
            dMaxY = dmaxy;
        }
        public void upDate(Point pt)//用点更新
        {
            dMinX = dMinX > pt.dX ? pt.dX : dMinX;
            dMinY = dMinY > pt.dY ? pt.dY : dMinY;
            dMaxX = dMaxX < pt.dX ? pt.dX : dMaxX;
            dMaxY = dMaxY < pt.dY ? pt.dY : dMaxY;
        }
        public void upDate(Extent extent)//拷贝更新
        {
            dMinX = dMinX > extent.dMinX ? extent.dMinX : dMinX;
            dMinY = dMinY > extent.dMinY ? extent.dMinY : dMinY;
            dMaxX = dMaxX < extent.dMaxX ? extent.dMaxX : dMaxX;
            dMaxY = dMaxY < extent.dMaxY ? extent.dMaxY : dMaxY;
        }
        public void upDate(double dminx, double dminy, double dmaxx, double dmaxy)//直接更新
        {
            dMinX = dminx;
            dMinY = dminy;
            dMaxX = dmaxx;
            dMaxY = dmaxy;
        }
        public void reSet()//直接更新
        {
            dMinX = 999999999;
            dMinY = 999999999;
            dMaxX = -9999999990;
            dMaxY = -999999999;
        }
        public void move(double dx, double dy)
        {
            dMinX += dx;
            dMinY += dy;
            dMaxX += dx;
            dMaxY += dy;
        }
        public double getWidth()
        {
            return dMaxX - dMinX;
        }
        public double getHeight()
        {
            return dMaxY- dMinY;
        }
        public double getCenterX()
        {
            return (dMaxX+ dMinX)/2.0;
        }
        public double getCenterY()
        {
            return (dMaxY + dMinY) / 2.0;
        }
        public bool inExtent(double x,double y)//坐标是否在范围内判断
        {
            if (x >= dMinX && x <= dMaxX && y >= dMinY && y <= dMaxY)
                return true;
            else
                return false;
        }
    }
}
